package test_slice

import "fmt"

func Do() {

	fmt.Println("切片测试")

	//初始化
	s1 := []int{1, 2, 3}
	printSlice(s1)

	//追加
	s1 = append(s1, 4)
	printSlice(s1)

	//make初始化切片(2倍扩容)
	s2 := make([]int, len(s1), cap(s1)*2)
	printSlice(s2)

	//切片拷贝
	copy(s2, s1)
	printSlice(s2)

	//子切片
	s3 := s2[0:2]
	printSlice(s3)
}

func printSlice(s []int) {
	for _, v := range s {
		fmt.Print(v)
	}
	fmt.Printf("切片slice: addr=%d  size=%d cap=%d \n", &s, len(s), cap(s))
}
